const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { ModuleFederationPlugin } = require("webpack").container;

module.exports = {
  mode: "development",
  entry: "./main.js",
  output: {
    path: path.resolve(__dirname, "./dist"),
    publicPath: "auto",
  },
  module: {
    rules: [
      {
        test: /\.jsx?$/,
        loader: "babel-loader",
        exclude: /node_modules/,
        options: {
          presets: ["@babel/preset-react"],
        },
      },
    ],
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: "./index.html",
      title: "App Main",
      filename: "index.html",
    }),
    new ModuleFederationPlugin({
      name: "app",
      remotes: {
        app1: "app1@http://localhost:8888/app1.js",
        app2: "app2@http://localhost:9999/app2.js",
      },
      shared: { react: { singleton: true, eager: false }, 'react-dom': { singleton: true, eager: false } },
      // shared: { vue: { singleton: true } },
    }),
  ],
  devServer: {
    static: {
      directory: path.join(__dirname, "public"),
    },
    compress: true,
    port: 3000,
    host: "localhost",
  },
  resolve: {
    extensions: [".jsx", ".js"],
  },
  stats: "minimal",
};
